package cn.yl.api.server.util.redis;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.io.Serializable;

@Slf4j
@NoArgsConstructor
@AllArgsConstructor
@Data
public class RedisExpireData implements Serializable {
    private Object storeData;
    private Long expire;
    private Long dataTime;

    public RedisExpireData(Object data, Long expire) {
        this.storeData = data;
        this.expire = expire;
        this.dataTime = System.currentTimeMillis();
    }

    /**
     * @Description 获取对应的expire数据
     * @Param []
     * @Return java.lang.String
     */
    public Object getStoreData() {
        Long curr = System.currentTimeMillis();
        if (curr - this.dataTime > this.expire) {
            log.warn("当前数据已过期：" + this);
            return null;
        } else {
            return this.storeData;
        }
    }
}